package com.shujia.mr.kqzl;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

//<"1001-20230806",[60,55,62,...,0,...]>
public class KqzlReducer extends Reducer<Text, LongWritable, Text, LongWritable> {
    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        long sum = 0L;
        for (LongWritable value : values) {
            sum += value.get();
        }

        //对于该监测点这一天的PM2.5的值求和之后与24相除
        long avg_pm25 = sum / 24;
        context.write(key, new LongWritable(avg_pm25));
    }
}
